<template>
  <div class="home-container">
    <!-- header部分 -->
    <el-header class="home-header">
      <div class="header-content">
        <span class="header-title">我的应用</span>
        <div class="header-actions">
          <span class="username">{{ user?.username }}</span>
          <!-- 退出登录按钮 -->
          <el-button  class="logout-button" type="text" @click="handleLogout">退出登录</el-button>
        </div>
      </div>
    </el-header>
    <!-- main部分 -->
    <el-main>
      <h1>欢迎回来, {{ user?.username }}!</h1>
      <p>这里是您的主页内容</p>
    </el-main>
  </div>
</template>

<script setup lang="ts">
// 引入组件 computed
import { computed } from 'vue'
// 引入路由
import { useRouter } from 'vue-router'
// 引入用户信息
import { useAuthStore } from '@/store/auth'

// 拿到用户信息
const authStore = useAuthStore()
// 拿到router
const router = useRouter()

// 拿到用户信息通过pinia
const user = computed(() => authStore.user)

// 如果登出，触发pinia登出操作
const handleLogout = () => {
  authStore.logout()
}
</script>

<style scoped>
.home-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.logout-button  {
  color: #eeeeee;
}

.home-header {
  background-color: #409eff;
  color: white;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 20px;
}

.header-title {
  font-size: 20px;
  font-weight: bold;
}

.header-actions {
  display: flex;
  align-items: center;
}

.username {
  margin-right: 15px;
}
</style>
